package com.nineclock.system.entity;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@Slf4j
public class ExcelMemberListener extends AnalysisEventListener<ExcelMember> {

    private SysCompanyUserService companyUserService;

    public ExcelMemberListener(SysCompanyUserService companyUserService){
        this.companyUserService = companyUserService;
    }


    private List<ExcelMember> list = new ArrayList<>();

    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        list.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        //读取完成
        log.info(list.toString());
        //解析 并封装 数据，存储到数据库
        companyUserService.handleParsedData(list);

    }
}
